﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Entities;

namespace InsuranceVehicle.AdminSite
{
    public partial class ClaimReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            EmployeeInfo emp = new EmployeeInfo();
            emp = (EmployeeInfo)Session["Employee"];
            if (emp != null)
            {
                if (emp.Department == 1)
                {
                    Menu1.ShowElement = "all";
                }
                else
                {
                    Menu1.ShowElement = "no";
                }
                showAllClaim();

            }
            else
            {
                Response.Redirect("LoginAdmin.aspx");
            }

            if (!IsPostBack)
            {
               
            }
        }

 
        public void showAllClaim()
        {
            ClaimDataAccess cda = new ClaimDataAccess();
            List<ClaimInfo> listClaim = new List<ClaimInfo>();
            listClaim = cda.getAllClaim();

            Repeater1.DataSource = listClaim;
            Repeater1.DataBind();
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            if (chooseEndDate.IsEmpty || chooseStartDate.IsEmpty)
            {
                showAllClaim();
            }
            else
            {
                DateTime startDate = Convert.ToDateTime(chooseStartDate.SelectedDate.Value.ToShortDateString());
                DateTime endDate = Convert.ToDateTime(chooseEndDate.SelectedDate.Value.ToShortDateString());

                ClaimDataAccess cda = new ClaimDataAccess();
                List<ClaimInfo> listClaim = new List<ClaimInfo>();
                if (rdByDateOfClaim.Checked == true)
                {
                    listClaim = cda.getListClaimByDateClaimDate(startDate, endDate);
                    Repeater1.DataSource = listClaim;
                    Repeater1.DataBind();
                }
                else
                {
                    listClaim = cda.getListClaimByDateAccidentDate(startDate, endDate);
                    Repeater1.DataSource = listClaim;
                    Repeater1.DataBind();
                }
            }
            
            
        }

        protected void btnShowAll_Click(object sender, EventArgs e)
        {
            showAllClaim();
        }
    }
}